package wxy.studentmanage.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import wxy.studentmanage.bean.Clazz;
import wxy.studentmanage.bean.Grade;
import wxy.studentmanage.service.GradeService;
import wxy.studentmanage.service.UserService;

import java.util.List;

@Controller
@RequestMapping("/grade")
public class GradeController {
    @Autowired
    @Qualifier("GradeServiceImpl")
    private GradeService gradeService;
    @RequestMapping("/allGrade")
    public String allGrade(Model model){
       List<Grade> glist = gradeService.allGrade();
       model.addAttribute("glist",glist);
       System.out.println(glist);
       return "allGrade";
    }
    @RequestMapping("/toAddGrade")
    public String toAddGrade(){
        return "addGrade";
    }
    @RequestMapping("/AddGrade")
    public String AddGrade(Grade grade){
        System.out.println(grade);
        int i = gradeService.addGrade(grade);

        return "redirect:/grade/allGrade";
    }
    @RequestMapping("/toUpdateGrade/{userId}")
    public String toUpdateGrade(@PathVariable("userId") int wxy_id,Model model){
        System.out.println(wxy_id);
        Grade grade = gradeService.queryGradeById(wxy_id);
        System.out.println(grade);
        model.addAttribute("grade",grade);
        return "updateGrade";
    }
    @RequestMapping("updateGrade")
    public String updateGrade(Grade grade){
        System.out.println(grade);
        int i = gradeService.updateGrade(grade);
        return "redirect:/grade/allGrade";
    }
    @RequestMapping("/del/{userId}")
    public String deleteGradeById(@PathVariable("userId") int wxy_id){
        System.out.println(wxy_id);
        int i = gradeService.deleteGradeById(wxy_id);
        System.out.println(i);
        return "redirect:/grade/allGrade";
    }
}
